package com.landscope.issue.controller.wx;

import com.landscope.issue.controller.api.dto.LoginDto;
import com.landscope.issue.controller.api.dto.WxPhoneLoginDto;
import com.landscope.issue.controller.api.param.LoginParam;
import com.landscope.issue.controller.base.ResponseResult;
import com.landscope.issue.controller.wx.param.AppletAuthParam;
import com.landscope.issue.controller.wx.param.AppletBandingParam;
import com.landscope.issue.service.ApiUserService;
import com.landscope.issue.service.applet.ApiAppletLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RequestMapping("api/applet")
@RestController
@Api(tags = "4.小程序-用户")
@CrossOrigin
public class ApiAppletLoginController {

    @Resource
    private ApiUserService apiUserService;
    @Resource
    private ApiAppletLoginService apiAppletLoginService;

    /**
     * 登录
     *
     * @return {@link * @return java.lang.Object}
     * @throws
     * @author 瞿子朋
     * @date 2021/8/2 9:58
     * @version v1.0
     **/
    @ApiOperation(value = "4.1 终端授权获取凭证", notes = "终端授权获取凭证")
    @PostMapping("/login")
    public ResponseResult<LoginDto> login(@RequestBody LoginParam param) {
        return apiUserService.login(param);
    }

    /**
     * 绑定微信openid
     *
     * @param param
     * @return
     */
    @ApiOperation(value = "4.2 绑定微信", notes = "绑定微信")
    @PostMapping("/banding")
    public ResponseResult<LoginDto> banding(@RequestBody AppletBandingParam param) {
        return apiAppletLoginService.banding(param);
    }

    @ApiOperation(value = "4.3 微信授权", notes = "微信授权")
    @PostMapping("/auth")
    public ResponseResult<LoginDto> auth(@RequestBody AppletAuthParam param) {
        return apiAppletLoginService.auth(param);
    }

    @ApiOperation(value = "4.4 微信手机号登录", notes = "微信手机号登录")
    @PostMapping("/WxPhoneLogin")
    public ResponseResult<WxPhoneLoginDto> WxPhoneLogin(@RequestBody AppletAuthParam param) {
        return apiAppletLoginService.WxPhoneLogin(param);
    }
}
